package com.resataurant.Controller.Admin;

import com.resataurant.Service.AdminService;
import com.resataurant.Service.Impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
@WebServlet(name = "DelDishServlet", value = "/DelDishServlet")
public class DelDishServlet extends HttpServlet {
    AdminService adminService=new AdminServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");//防止中文乱码

        String DishId=request.getParameter("DishId");
        System.out.println("删除菜品"+DishId);
        request.getSession().setAttribute("DishName",adminService.searchDishById(DishId).getDishName());
        request.getSession().setAttribute("id",DishId);
        int sta=adminService.deleteDish(DishId);
        if (sta==1){
            request.getSession().setAttribute("message","删除成功");
            response.sendRedirect("delResult.jsp");
        }else {
            request.getSession().setAttribute("message","删除失败");
            response.sendRedirect("dishDetail.jsp");
        }
    }
}
